//
//  QYOCJSViewController.m
//  QYBaseProject
//
//  Created by Dxc_iOS on 2018/8/9.
//  Copyright © 2018年 代星创. All rights reserved.
//

#import "QYOCJSViewController.h"
#import <WebKit/WebKit.h>
#import <WKWebViewJavascriptBridge.h>
@interface QYOCJSViewController ()<WKNavigationDelegate>
{
    NSDictionary *respDic;
}
@property WKWebViewJavascriptBridge* bridge;
@property (nonatomic, strong)WKWebView *webView;

@end

@implementation QYOCJSViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"在线做题";
    self.view.backgroundColor = [UIColor whiteColor];
    [self creatWebView];
}
- (void)creatWebView
{
    if (_bridge) { return; }

    
    self.webView = [[WKWebView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    _webView.navigationDelegate = self;
    NSString* htmlPath = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"html"];
    NSString* appHtml = [NSString stringWithContentsOfFile:htmlPath encoding:NSUTF8StringEncoding error:nil];
    NSURL *baseURL = [NSURL fileURLWithPath:htmlPath];
    [_webView loadHTMLString:appHtml baseURL:baseURL];
    [self.view addSubview:_webView];
    
    [WKWebViewJavascriptBridge enableLogging];
    
    _bridge = [WKWebViewJavascriptBridge bridgeForWebView:self.webView];
    [_bridge setWebViewDelegate:self];
    
    
     [_bridge callHandler:@"getQuestionData" data:respDic];
    
    
    [_bridge registerHandler:@"tapAction" handler:^(id data, WVJBResponseCallback responseCallback) {
         NSLog(@"获取的data=  %@", data);
        
//        responseCallback(@"传递给JS");
    }];
    
    
    
    
    
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
